package sy.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * SysUnit entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "sys_unit", catalog = "ssh")
public class SysUnit implements java.io.Serializable {

	// Fields

	private String id;
	private SysBuilding sysBuilding;
	private String name;
	private String code;
	private String address;

	@JsonProperty(value = "buildingName")
    private String buildingName;
	
	@JsonProperty(value = "projectName")
    private String projectName;

	// Constructors

	/** default constructor */
	public SysUnit() {
	}

	/** full constructor */
	public SysUnit(SysBuilding sysBuilding, String name, String code,
			String address) {
		this.sysBuilding = sysBuilding;
		this.name = name;
		this.code = code;
		this.address = address;
	}

	// Property accessors
	@GenericGenerator(name = "generator", strategy = "uuid.string")
	@Id
	@Column(name = "id", unique = true, nullable = false, length = 64)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "building")
	public SysBuilding getSysBuilding() {
		return this.sysBuilding;
	}

	public void setSysBuilding(SysBuilding sysBuilding) {
		this.sysBuilding = sysBuilding;
	}

	@Column(name = "name")
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "code")
	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Column(name = "address")
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	@Transient
	public String getBuildingName() {
		if(getSysBuilding()==null){
			return "";
		}
		return getSysBuilding().getName();
	}

	public void setBuildingName(String buildingName) {
		this.buildingName = buildingName;
	}
	
	@Transient
    public String getProjectName() {
    	return  getSysBuilding().getProjectName();
	}

	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}
	
}